import kk from "../page/errorpage/404.vue";

export const addRouter = (routerlist: any[]) => {
  const router: any[] = [];
  try {
    routerlist.forEach((e: any) => {
      let e_new: any = {
        path: e.url,
        name: e.name,
        component: () => import(`../page/${e.component}.vue`),
      };
      if (e.children) {
        const children = addRouter(e.children);
        e_new = { ...e_new, children: children };
      }
      if (e.redirect) {
        e_new = { ...e_new, redirect: e.redirect };
      }
      if (e.generatemenu === 0) {
        e_new = { ...e_new, hidden: true };
      }
      if (e.icon !== "" && e.title !== "") {
        e_new = { ...e_new, meta: { title: e.title, icon: e.icon } };
      } else if (e.title !== "" && e.icon === "") {
        e_new = { ...e_new, meta: { title: e.title } };
      }
      router.push(e_new);
    });
  } catch (error) {
    console.error(error);
    return [];
  }
  return router;
};
